HFA & Weight Calclulation for 21st century
year_list = c(2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020)
# list for saving hfa and weight in different years
hfa_list = c()
weight_list = c()
for (x in year_list){
home_wins = 0
games = 0
first_game_index = 1
scores = raw_data[which(raw_data$season==x),]
# Iterate through games - first index can be changed to eliminate early seasons where scores are extreme
for(i in first_game_index:nrow(scores)) {
# Count number of games that do not end in ties
if(scores$home_score[i] != scores$away_score[i]) { games = games + 1 }
# Count number of games where home team wins
if(scores$home_score[i] > scores$away_score[i]) { home_wins = home_wins + 1 }
}
home_win_prob = home_wins / games # Calculate home win probability where outcome was not a tie
hfa = -400*log10(1/home_win_prob - 1) # Calculate number of Elo points added to home team
hfa_list <- append(hfa_list,hfa)
starting_weight = 0 # Lower bound for weight ranges to be tested - generally set equal to 0
iterations = 100 # Number of k values to test
step_size = 0.1 # Amount to increment k by at each step
first_game_index = 1
# Initialize data frame to store k values and corresponding error
errors = data.frame(matrix(ncol = 2, nrow = iterations))
colnames(errors) = c("weight", "error")
errors$weight = starting_weight + (1:iterations)*step_size
errors$error = NA
# Iterate through all potential k values that are being tested
for(counter in 1:iterations) {
weight = starting_weight + counter*step_size # Calculate k value for current iteration
error = 0 # Reset error for current iteration
elos = read.table("nba_initial_elos.csv", header=TRUE, sep=",") # Reset initial Elo ratings
# Iterate through games - first index can be changed to eliminate early seasons in a league where early results tend to be extreme
for(i in first_game_index:nrow(scores)) {
# Find indices corresponding to home and away teams for current game
home_index = which(elos$team == scores$home_team[i])
away_index = which(elos$team == scores$away_team[i])
# Find home and away team Elo ratings
home_elo = elos$rating[home_index]
away_elo = elos$rating[away_index]
# Calculate home team win probability
win_prob = 1 / (10^((away_elo - (home_elo + hfa*scores$neutral[i]))/400) + 1)
# Calculate actual margin of victory - must be positive
score_diff = abs(scores$home_score[i] - scores$away_score[i])
# Determine home team result
if(scores$home_score[i] > scores$away_score[i]) {
home_result = 1 # Home team wins
} else if(scores$home_score[i] < scores$away_score[i]) {
home_result = 0 # Home team loses
} else {
home_result = 0.5 # Tie
}
# Add squared error between home result and predicted probability of home team winning to SSE
error = error + (home_result - win_prob)^2
# Calculate amount each team's Elo rating is adjusted by
home_elo_adjustment = weight * log(score_diff + 1) * (home_result - win_prob)
# Adjust Elo ratings - add point to winner and subtract points from loser
elos$rating[home_index] = elos$rating[home_index] + home_elo_adjustment
elos$rating[away_index] = elos$rating[away_index] - home_elo_adjustment
# Adjust Elo ratings at end of season to regress 1/3 of the way towards 1500
if(i < nrow(scores) && scores$season[i+1] > scores$season[i]) {
for(j in 1:nrow(elos)) {
if(scores$season[i] >= elos$inaugural_season[j]) {
elos$rating[j] = elos$rating[j] - (elos$rating[j] - 1500)/3
}
}
existing_teams = elos[which(elos$inaugural_season <= (scores$season[i] + 1)),]
expansion_adjustment = -1*(mean(existing_teams$rating) - 1500)
for(j in 1:nrow(elos)) {
if((scores$season[i] + 1) >= elos$inaugural_season[j]) {
elos$rating[j] = elos$rating[j] + expansion_adjustment
}
}
}
}
errors$error[counter] = error # Store error for current iteration
}
# Choose and print optimal weight based on value that had the lowest SSE
weight = errors$weight[which(errors$error == min(errors$error))]
weight_list <- append(weight_list,weight)
}
print(hfa_list)
## [1] 68.14165 64.13962 90.41023 85.61199 71.86992 76.27353 66.90464 77.83927
## [9] 79.29028 69.77472 76.19808 65.46320 80.18853 55.52015 53.14886 66.26620
## [17] 58.13276 60.99658 63.73097 32.62010 32.43418
print(weight_list)
## [1] 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0
## [16] 10.0 9.9 10.0 10.0 10.0 10.0
Elo Ratings Calclulation for 21st century
# Use list to store average elo ratings for each year from 2000 to 2020
stack=list()
for(teamN in team_name){
inital_year=2000
# Optimal weight from code above. If the above code is run first, the line below can be commented out. Otherwise, you can type the optimal k-value below without needing to run the chunk of code above.
for(i in 1:nrow(Adjustment)){
weight = Adjustment[i,"weight_list"]
hfa =Adjustment[i,"hfa_list"]
# Select team and season to follow for a period of time
team = teamN
first_season = inital_year
last_season = inital_year
inital_year=inital_year+1
# Read in initial team Elo ratings and history of games
elos = read.table("nba_initial_elos.csv", header=TRUE, sep=",")
scores =raw_data[which(raw_data$season<=first_season),]
# Create data frame to store information for team specified above
team_results = data.frame(matrix(ncol = 8, nrow = 0))
colnames(team_results) = c("opponent", "pregame_elo", "win_probability", "result", "team_score", "opponent_score", "elo_adjustment", "postgame_elo")
# Iterate through all games in the sport's history
for(i in 1:nrow(scores)) {
# Find indices corresponding to home and away teams for current game
home_index = which(elos$team == scores$home_team[i])
away_index = which(elos$team == scores$away_team[i])
# Find home and away team Elo ratings
home_elo = elos$rating[home_index]
away_elo = elos$rating[away_index]
# Calculate home team win probability
win_prob = 1 / (10^((away_elo - (home_elo + hfa*scores$neutral[i]))/400) + 1)
# Calculate actual margin of victory - must be positive
score_diff = abs(scores$home_score[i] - scores$away_score[i])
# Determine home team result
if(scores$home_score[i] > scores$away_score[i]) {
home_result = 1 # Home team wins
} else if(scores$home_score[i] < scores$away_score[i]) {
home_result = 0 # Home team loses
} else {
home_result = 0.5 # Tie
}
# Calculate amount each team's Elo rating is adjusted by
home_elo_adjustment = weight * log(score_diff + 1) * (home_result - win_prob)
# Adjust Elo ratings - add point to winner and subtract points from loser
elos$rating[home_index] = elos$rating[home_index] + home_elo_adjustment
elos$rating[away_index] = elos$rating[away_index] - home_elo_adjustment
# Add game information to team result data frame for each team game of the team specified above if team and season both match
if(scores$season[i] >= first_season & scores$season[i] <= last_season & (scores$home_team[i] == team | scores$away_team[i] == team)) {
if(scores$home_team[i] == team) { # If specified team was at home
team_results[nrow(team_results) + 1,] = c(scores$away_team[i], elos$rating[home_index] - home_elo_adjustment, win_prob, home_result, scores$home_score[i], scores$away_score[i], home_elo_adjustment, elos$rating[home_index])
} else { # If specified team was away
team_results[nrow(team_results) + 1,] = c(scores$home_team[i], elos$rating[away_index] + home_elo_adjustment, 1-win_prob, 1-home_result, scores$away_score[i], scores$home_score[i], -1*home_elo_adjustment, elos$rating[away_index])
}
}
# Adjust Elo ratings at end of season to regress 1/3 of the way towards 1500
if(i < nrow(scores) && scores$season[i+1] > scores$season[i]) { # New season
for(j in 1:nrow(elos)) { # For each team
if(scores$season[i] >= elos$inaugural_season[j]) { # Check if team existed
# Move each team's Elo rating back towards 1500 by 1/3 of the difference
elos$rating[j] = elos$rating[j] - (elos$rating[j] - 1500)/3
}
}
# Identify all teams that existed at beginning of following season
existing_teams = elos[which(elos$inaugural_season <= (scores$season[i] + 1)),]
# Calculate amount each team's Elo rating must be adjusted by to make mean 1500
expansion_adjustment = -1*(mean(existing_teams$rating) - 1500)
# Perform expansion adjustment on teams that existed at beginning of following season
for(j in 1:nrow(elos)) { # For each team
if((scores$season[i] + 1) >= elos$inaugural_season[j]) { # Check if team existed
elos$rating[j] = elos$rating[j] + expansion_adjustment # Update ratings if so
}
}
}
}
# Change data type to numeric
temp=transform(team_results,postgame_elo=as.numeric(postgame_elo))
# Store the elo into the list
stack=append(stack,mean(temp$postgame_elo))
}
}
import elo data
df=read.csv("elo.csv")
Get Descriptive Statistics and store them in the descriptive
dataframe
# Store everything in the descriptive_stat dataframe
mean_df=as.data.frame(do.call(rbind,mean_stack))
colnames(mean_df)="mean"
sd_df=as.data.frame(do.call(rbind,sd_stack))
colnames(sd_df)="sd"
median_df=as.data.frame(do.call(rbind,median_stack))
colnames(median_df)="median"
descriptive_stat=cbind(colnames(df),mean_df,sd_df,median_df)
colnames(descriptive_stat)=c("team","mean","sd","median")
store the Descriptive Statistics
write.csv(descriptive_stat,"descriptive.csv",row.names = FALSE)
import Descriptive Statistics
descriptive_stat=read.csv("descriptive.csv")
Reset the team name since the names have some changes
team_name=colnames(df)
Calculate autocrrelation and durbinWatsontest for the linear
model
library(car)
## Loading required package: carData
for (i in team_name){
cat(paste("Team: ",i))
cat("\n")
#Construct the linear model
cur_model=lm(df[,i]~df[,"year"])
# formating
print(durbinWatsonTest(cur_model))
cat("\n")
cat("\n")
}
## Team: Orlando.Magic
## lag Autocorrelation D-W Statistic p-value
## 1 0.7078625 0.581168 0
## Alternative hypothesis: rho != 0
##
##
## Team: Atlanta.Hawks
## lag Autocorrelation D-W Statistic p-value
## 1 0.6832184 0.6229795 0
## Alternative hypothesis: rho != 0
##
##
## Team: Brooklyn.Nets
## lag Autocorrelation D-W Statistic p-value
## 1 0.4444372 0.8767611 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: Toronto.Raptors
## lag Autocorrelation D-W Statistic p-value
## 1 0.5082855 0.8085398 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: New.York.Knicks
## lag Autocorrelation D-W Statistic p-value
## 1 0.3163093 1.187897 0.024
## Alternative hypothesis: rho != 0
##
##
## Team: Dallas.Mavericks
## lag Autocorrelation D-W Statistic p-value
## 1 0.3304898 1.163481 0.024
## Alternative hypothesis: rho != 0
##
##
## Team: Houston.Rockets
## lag Autocorrelation D-W Statistic p-value
## 1 0.1085938 1.329416 0.072
## Alternative hypothesis: rho != 0
##
##
## Team: San.Antonio.Spurs
## lag Autocorrelation D-W Statistic p-value
## 1 0.6529772 0.5509981 0
## Alternative hypothesis: rho != 0
##
##
## Team: Chicago.Bulls
## lag Autocorrelation D-W Statistic p-value
## 1 0.7297002 0.3983664 0
## Alternative hypothesis: rho != 0
##
##
## Team: Utah.Jazz
## lag Autocorrelation D-W Statistic p-value
## 1 0.55544 0.7217189 0
## Alternative hypothesis: rho != 0
##
##
## Team: Portland.Trailblazers
## lag Autocorrelation D-W Statistic p-value
## 1 0.5259033 0.8019058 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: Golden.State.Warriors
## lag Autocorrelation D-W Statistic p-value
## 1 0.6095012 0.6132759 0
## Alternative hypothesis: rho != 0
##
##
## Team: Memphis.Grizzlies
## lag Autocorrelation D-W Statistic p-value
## 1 0.6370672 0.7025395 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: Philadelphia.76ers
## lag Autocorrelation D-W Statistic p-value
## 1 0.654117 0.5185056 0
## Alternative hypothesis: rho != 0
##
##
## Team: Boston.Celtics
## lag Autocorrelation D-W Statistic p-value
## 1 0.4408933 1.093947 0.006
## Alternative hypothesis: rho != 0
##
##
## Team: Cleveland.Cavaliers
## lag Autocorrelation D-W Statistic p-value
## 1 0.5886311 0.7720176 0.004
## Alternative hypothesis: rho != 0
##
##
## Team: Charlotte.Hornets
## lag Autocorrelation D-W Statistic p-value
## 1 0.4752125 0.8775541 0
## Alternative hypothesis: rho != 0
##
##
## Team: Miami.Heat
## lag Autocorrelation D-W Statistic p-value
## 1 0.4750486 1.021841 0.004
## Alternative hypothesis: rho != 0
##
##
## Team: Oklahoma.City.Thunder
## lag Autocorrelation D-W Statistic p-value
## 1 0.5584059 0.7497431 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: Los.Angeles.Lakers
## lag Autocorrelation D-W Statistic p-value
## 1 0.7069464 0.4759136 0
## Alternative hypothesis: rho != 0
##
##
## Team: Denver.Nuggets
## lag Autocorrelation D-W Statistic p-value
## 1 0.6666633 0.6630547 0
## Alternative hypothesis: rho != 0
##
##
## Team: Phoenix.Suns
## lag Autocorrelation D-W Statistic p-value
## 1 0.4045231 0.9464731 0.004
## Alternative hypothesis: rho != 0
##
##
## Team: Los.Angeles.Clippers
## lag Autocorrelation D-W Statistic p-value
## 1 0.5917471 0.8028749 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: Washington.Wizards
## lag Autocorrelation D-W Statistic p-value
## 1 0.5851073 0.7680514 0
## Alternative hypothesis: rho != 0
##
##
## Team: Detroit.Pistons
## lag Autocorrelation D-W Statistic p-value
## 1 0.6492766 0.5486223 0
## Alternative hypothesis: rho != 0
##
##
## Team: Indiana.Pacers
## lag Autocorrelation D-W Statistic p-value
## 1 0.4859199 1.015781 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: Minnesota.Timberwolves
## lag Autocorrelation D-W Statistic p-value
## 1 0.6335969 0.7228651 0.002
## Alternative hypothesis: rho != 0
##
##
## Team: Milwaukee.Bucks
## lag Autocorrelation D-W Statistic p-value
## 1 0.5960961 0.6605117 0
## Alternative hypothesis: rho != 0
##
##
## Team: Sacramento.Kings
## lag Autocorrelation D-W Statistic p-value
## 1 0.790246 0.3386508 0
## Alternative hypothesis: rho != 0
##
##
## Team: New.Orleans.Pelicans
## lag Autocorrelation D-W Statistic p-value
## 1 0.254611 1.455674 0.132
## Alternative hypothesis: rho != 0
Get optimal order of autoregressive model
library(car)
# Create a list to store the optimal order
opt_order=list()
for(i in team_name){
# Construct the autoregressive model
model_time=ar.ols(df[,i],order.max = 6, demean = F, intercept = T)
# formating
cat(paste("\nTeam: ",i),"\n")
cat("\n")
print(model_time)
cat("\n")
cat("\n")
# store the order into list
opt_order=append(opt_order,model_time$order)
}
##
## Team: Orlando.Magic
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2
## 1.0700 -0.4469
##
## Intercept: 548.2 (224)
##
## Order selected 2 sigma^2 estimated as 4470
##
##
##
## Team: Atlanta.Hawks
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5
## 0.8293 -0.0028 -0.4624 -0.0372 0.2048
##
## Intercept: 702.6 (283.4)
##
## Order selected 5 sigma^2 estimated as 3078
##
##
##
## Team: Brooklyn.Nets
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6
## 0.6474 -0.0107 -0.5359 -0.2100 0.4763 -0.2263
##
## Intercept: 1221 (384.6)
##
## Order selected 6 sigma^2 estimated as 2504
##
##
##
## Team: Toronto.Raptors
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3
## 0.8775 -0.0234 -0.1993
##
## Intercept: 521.3 (252.3)
##
## Order selected 3 sigma^2 estimated as 3439
##
##
##
## Team: New.York.Knicks
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1
## 0.3608
##
## Intercept: 904.2 (273.1)
##
## Order selected 1 sigma^2 estimated as 3830
##
##
##
## Team: Dallas.Mavericks
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5
## 1.0729 -0.8805 0.4968 0.2662 -0.0231
##
## Intercept: 85.29 (319.4)
##
## Order selected 5 sigma^2 estimated as 1568
##
##
##
## Team: Houston.Rockets
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6
## 0.3829 -0.3951 -0.0897 -0.6887 0.7449 -0.7839
##
## Intercept: 2875 (742.3)
##
## Order selected 6 sigma^2 estimated as 2253
##
##
##
## Team: San.Antonio.Spurs
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4
## 0.8795 -0.2906 0.0830 -0.8105
##
## Intercept: 1898 (628)
##
## Order selected 4 sigma^2 estimated as 1360
##
##
##
## Team: Chicago.Bulls
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1
## 0.7219
##
## Intercept: 415.4 (179)
##
## Order selected 1 sigma^2 estimated as 3771
##
##
##
## Team: Utah.Jazz
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2
## 0.9136 -0.4152
##
## Intercept: 774.3 (299.9)
##
## Order selected 2 sigma^2 estimated as 2494
##
##
##
## Team: Portland.Trailblazers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6
## 0.6971 -0.4423 0.1689 -0.1047 0.0678 -0.0530
##
## Intercept: 1024 (506.4)
##
## Order selected 6 sigma^2 estimated as 1957
##
##
##
## Team: Golden.State.Warriors
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1
## 0.7605
##
## Intercept: 372.3 (194.6)
##
## Order selected 1 sigma^2 estimated as 6935
##
##
##
## Team: Memphis.Grizzlies
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6
## 0.9139 0.4658 -1.3497 0.2278 0.6656 -0.4960
##
## Intercept: 860.1 (314.2)
##
## Order selected 6 sigma^2 estimated as 1346
##
##
##
## Team: Philadelphia.76ers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5
## 1.2578 -1.1063 0.8756 -1.1389 0.4537
##
## Intercept: 942.5 (312.3)
##
## Order selected 5 sigma^2 estimated as 1887
##
##
##
## Team: Boston.Celtics
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4
## 0.5609 -0.2759 0.1522 -0.4906
##
## Intercept: 1629 (414.4)
##
## Order selected 4 sigma^2 estimated as 4503
##
##
##
## Team: Cleveland.Cavaliers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4
## 0.5780 -0.4117 0.0644 -0.4807
##
## Intercept: 1874 (406.5)
##
## Order selected 4 sigma^2 estimated as 6269
##
##
##
## Team: Charlotte.Hornets
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2
## 0.6590 -0.4131
##
## Intercept: 1072 (269.2)
##
## Order selected 2 sigma^2 estimated as 3134
##
##
##
## Team: Miami.Heat
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3
## 0.4928 -0.0729 -0.4068
##
## Intercept: 1530 (361.6)
##
## Order selected 3 sigma^2 estimated as 4802
##
##
##
## Team: Oklahoma.City.Thunder
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1
## 0.6664
##
## Intercept: 512.2 (273.8)
##
## Order selected 1 sigma^2 estimated as 6454
##
##
##
## Team: Los.Angeles.Lakers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3
## 0.9351 0.2284 -0.5602
##
## Intercept: 616.1 (182.3)
##
## Order selected 3 sigma^2 estimated as 3015
##
##
##
## Team: Denver.Nuggets
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5
## 1.0182 -0.5624 0.0248 0.1845 -0.3073
##
## Intercept: 990.7 (304.3)
##
## Order selected 5 sigma^2 estimated as 1193
##
##
##
## Team: Phoenix.Suns
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1
## 0.6631
##
## Intercept: 509.2 (258.9)
##
## Order selected 1 sigma^2 estimated as 7621
##
##
##
## Team: Los.Angeles.Clippers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3
## 1.2054 -0.5266 0.0100
##
## Intercept: 479 (207)
##
## Order selected 3 sigma^2 estimated as 2857
##
##
##
## Team: Washington.Wizards
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5
## 0.7534 -0.2765 0.0511 -0.2146 -0.2201
##
## Intercept: 1301 (406.9)
##
## Order selected 5 sigma^2 estimated as 1808
##
##
##
## Team: Detroit.Pistons
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6
## 0.7734 0.0502 -0.0178 -0.3711 0.2493 -0.0945
##
## Intercept: 590.3 (261.5)
##
## Order selected 6 sigma^2 estimated as 2173
##
##
##
## Team: Indiana.Pacers
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4
## 0.3621 0.1419 -0.2554 -0.2929
##
## Intercept: 1580 (404.4)
##
## Order selected 4 sigma^2 estimated as 1618
##
##
##
## Team: Minnesota.Timberwolves
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6
## 0.5536 -0.1773 -0.2925 0.0145 0.4705 -0.5237
##
## Intercept: 1350 (335.3)
##
## Order selected 6 sigma^2 estimated as 2552
##
##
##
## Team: Milwaukee.Bucks
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1
## 0.6983
##
## Intercept: 449.6 (253.3)
##
## Order selected 1 sigma^2 estimated as 4772
##
##
##
## Team: Sacramento.Kings
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6
## 0.1780 0.0992 -0.0784 0.3816 0.0660 -0.4292
##
## Intercept: 1110 (275.7)
##
## Order selected 6 sigma^2 estimated as 984
##
##
##
## Team: New.Orleans.Pelicans
##
##
## Call:
## ar.ols(x = df[, i], order.max = 6, demean = F, intercept = T)
##
## Coefficients:
## 1 2 3 4 5 6
## 0.1713 -0.1348 -0.2279 -0.2924 0.0340 -0.3546
##
## Intercept: 2665 (723.5)
##
## Order selected 6 sigma^2 estimated as 2177
Durbin-Watson test statistic and model
library("tidyverse")
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ tibble 3.1.8 ✔ dplyr 1.0.9
## ✔ tidyr 1.2.0 ✔ stringr 1.4.1
## ✔ readr 2.1.2 ✔ forcats 0.5.2
## ✔ purrr 0.3.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ dplyr::recode() masks car::recode()
## ✖ purrr::some() masks car::some()
# create a list to store the prediction for the next year average elo ratings
predict_result=list()
#index for the optimal order list
count=1
# loop to go over each team
for(i in team_name){
# create a list to store the each lag column like lag1, lag2...
group=list()
# each team's elo ratings dataframe
current_team=df[i]
# optimal order
counter<-opt_order[[count]]
# create lag column based on the optimal order
for(j in 1:counter){
# create the lag column using dplyr
current_team<-current_team %>%
dplyr::mutate("lag{j}":=lag(df[,i],n=j,default=NA))
# construct the lag column name string for later use and store it in the group list
temp=paste("lag",j,sep = "")
group=append(group,temp)
}
# go to the next optimal order for the next team
count=count+1
# construct the model formula to general model
mymodel<-as.formula(paste(i,paste(group,collapse = "+"),sep = "~"))
# use model lm function and model formula to generate the model
current_model=lm(mymodel,data=current_team)
# formmating
cat(paste("Team: ",i))
cat("\n")
# print the summary of the model
print(summary(current_model))
# get the prediction for the next year elo ratings
prediction=tail(current_team,n=1)
cat("The prediction for 2021 is the following\n")
# output the predicted next year elo ratings
print(predict(current_model,prediction))
# store the predicted result into list
predict_result=append(predict_result,predict(current_model,prediction))
cat("\n")
# run the durbinwatsonTest
print(durbinWatsonTest(current_model))
cat("\n")
cat("\n")
}
## Team: Orlando.Magic
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -129.883 -43.798 9.296 52.084 92.512
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 548.2074 244.1129 2.246 0.039200 *
## lag1 1.0700 0.2332 4.588 0.000303 ***
## lag2 -0.4469 0.2324 -1.922 0.072533 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 72.86 on 16 degrees of freedom
## (2 observations deleted due to missingness)
## Multiple R-squared: 0.6207, Adjusted R-squared: 0.5733
## F-statistic: 13.09 on 2 and 16 DF, p-value: 0.000428
##
## The prediction for 2021 is the following
## 21
## 1493.33
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.08751531 2.054502 0.814
## Alternative hypothesis: rho != 0
##
##
## Team: Atlanta.Hawks
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -80.55 -38.04 -16.41 40.38 146.03
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 702.552484 358.429862 1.960 0.0784 .
## lag1 0.829292 0.279104 2.971 0.0140 *
## lag2 -0.002759 0.383349 -0.007 0.9944
## lag3 -0.462419 0.374308 -1.235 0.2449
## lag4 -0.037202 0.403784 -0.092 0.9284
## lag5 0.204818 0.297235 0.689 0.5064
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 70.18 on 10 degrees of freedom
## (5 observations deleted due to missingness)
## Multiple R-squared: 0.6595, Adjusted R-squared: 0.4893
## F-statistic: 3.874 on 5 and 10 DF, p-value: 0.03258
##
## The prediction for 2021 is the following
## 21
## 1449.385
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.1165448 2.135864 0.87
## Alternative hypothesis: rho != 0
##
##
## Team: Brooklyn.Nets
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -60.090 -41.876 -9.217 32.919 111.090
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1220.67615 526.67341 2.318 0.0491 *
## lag1 0.64744 0.27456 2.358 0.0461 *
## lag2 -0.01073 0.31975 -0.034 0.9741
## lag3 -0.53591 0.31813 -1.685 0.1306
## lag4 -0.21001 0.30762 -0.683 0.5141
## lag5 0.47629 0.32086 1.484 0.1760
## lag6 -0.22630 0.25485 -0.888 0.4005
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 68.52 on 8 degrees of freedom
## (6 observations deleted due to missingness)
## Multiple R-squared: 0.649, Adjusted R-squared: 0.3857
## F-statistic: 2.465 on 6 and 8 DF, p-value: 0.1185
##
## The prediction for 2021 is the following
## 21
## 1467.772
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.3890731 2.358337 0.886
## Alternative hypothesis: rho != 0
##
##
## Team: Toronto.Raptors
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -109.33 -30.75 12.38 41.02 83.08
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 521.32031 286.07583 1.822 0.08983 .
## lag1 0.87755 0.25440 3.450 0.00391 **
## lag2 -0.02344 0.35904 -0.065 0.94888
## lag3 -0.19932 0.28243 -0.706 0.49193
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 66.49 on 14 degrees of freedom
## (3 observations deleted due to missingness)
## Multiple R-squared: 0.6588, Adjusted R-squared: 0.5857
## F-statistic: 9.011 on 3 and 14 DF, p-value: 0.001416
##
## The prediction for 2021 is the following
## 21
## 1628.819
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.01541888 1.868053 0.574
## Alternative hypothesis: rho != 0
##
##
## Team: New.York.Knicks
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -107.200 -33.972 0.043 16.756 150.296
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 904.2492 287.8373 3.142 0.00564 **
## lag1 0.3608 0.2024 1.782 0.09156 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 65.24 on 18 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.15, Adjusted R-squared: 0.1028
## F-statistic: 3.177 on 1 and 18 DF, p-value: 0.09156
##
## The prediction for 2021 is the following
## 21
## 1377.629
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.1376077 1.569834 0.228
## Alternative hypothesis: rho != 0
##
##
## Team: Dallas.Mavericks
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -52.839 -24.192 -5.515 14.407 83.610
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 85.29450 404.03740 0.211 0.83704
## lag1 1.07295 0.26939 3.983 0.00259 **
## lag2 -0.88049 0.39620 -2.222 0.05050 .
## lag3 0.49677 0.41936 1.185 0.26356
## lag4 0.26618 0.37030 0.719 0.48870
## lag5 -0.02313 0.38972 -0.059 0.95385
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 50.09 on 10 degrees of freedom
## (5 observations deleted due to missingness)
## Multiple R-squared: 0.7866, Adjusted R-squared: 0.6798
## F-statistic: 7.37 on 5 and 10 DF, p-value: 0.003875
##
## The prediction for 2021 is the following
## 21
## 1537.109
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.1438985 2.246477 0.946
## Alternative hypothesis: rho != 0
##
##
## Team: Houston.Rockets
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -66.470 -40.707 8.202 35.983 112.950
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2874.86313 1016.48613 2.828 0.0222 *
## lag1 0.38293 0.38574 0.993 0.3499
## lag2 -0.39509 0.46644 -0.847 0.4216
## lag3 -0.08973 0.49966 -0.180 0.8619
## lag4 -0.68869 0.59113 -1.165 0.2776
## lag5 0.74495 0.48896 1.524 0.1661
## lag6 -0.78395 0.42491 -1.845 0.1023
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 64.99 on 8 degrees of freedom
## (6 observations deleted due to missingness)
## Multiple R-squared: 0.5266, Adjusted R-squared: 0.1716
## F-statistic: 1.483 on 6 and 8 DF, p-value: 0.2953
##
## The prediction for 2021 is the following
## 21
## 1453.666
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.05963411 1.744307 0.382
## Alternative hypothesis: rho != 0
##
##
## Team: San.Antonio.Spurs
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -62.496 -25.699 -3.759 12.931 77.660
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1897.89288 747.43059 2.539 0.02598 *
## lag1 0.87953 0.24733 3.556 0.00395 **
## lag2 -0.29057 0.35733 -0.813 0.43196
## lag3 0.08296 0.35409 0.234 0.81871
## lag4 -0.81052 0.37615 -2.155 0.05219 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 43.9 on 12 degrees of freedom
## (4 observations deleted due to missingness)
## Multiple R-squared: 0.7504, Adjusted R-squared: 0.6671
## F-statistic: 9.017 on 4 and 12 DF, p-value: 0.001332
##
## The prediction for 2021 is the following
## 21
## 1510.932
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.008788928 1.906495 0.704
## Alternative hypothesis: rho != 0
##
##
## Team: Chicago.Bulls
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -111.855 -38.155 -7.505 34.493 139.689
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 415.3962 188.6589 2.202 0.041 *
## lag1 0.7219 0.1287 5.610 2.53e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 64.73 on 18 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.6361, Adjusted R-squared: 0.6159
## F-statistic: 31.47 on 1 and 18 DF, p-value: 2.531e-05
##
## The prediction for 2021 is the following
## 21
## 1397.138
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.1782521 1.61567 0.296
## Alternative hypothesis: rho != 0
##
##
## Team: Utah.Jazz
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -131.757 -17.475 2.464 28.021 82.945
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 774.3439 326.7613 2.370 0.03071 *
## lag1 0.9136 0.2379 3.840 0.00144 **
## lag2 -0.4152 0.2325 -1.785 0.09315 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 54.42 on 16 degrees of freedom
## (2 observations deleted due to missingness)
## Multiple R-squared: 0.4857, Adjusted R-squared: 0.4214
## F-statistic: 7.554 on 2 and 16 DF, p-value: 0.004899
##
## The prediction for 2021 is the following
## 21
## 1567.61
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.02094699 1.885016 0.638
## Alternative hypothesis: rho != 0
##
##
## Team: Portland.Trailblazers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -79.838 -23.193 6.735 28.045 91.984
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1024.37752 693.43988 1.477 0.1779
## lag1 0.69707 0.30862 2.259 0.0538 .
## lag2 -0.44227 0.40872 -1.082 0.3108
## lag3 0.16894 0.47024 0.359 0.7287
## lag4 -0.10474 0.43105 -0.243 0.8141
## lag5 0.06779 0.38650 0.175 0.8651
## lag6 -0.05305 0.27819 -0.191 0.8535
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 60.57 on 8 degrees of freedom
## (6 observations deleted due to missingness)
## Multiple R-squared: 0.4691, Adjusted R-squared: 0.07094
## F-statistic: 1.178 on 6 and 8 DF, p-value: 0.4033
##
## The prediction for 2021 is the following
## 21
## 1489.709
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.2811096 2.404132 0.884
## Alternative hypothesis: rho != 0
##
##
## Team: Golden.State.Warriors
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -228.266 -17.649 7.724 41.909 140.660
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 372.2937 205.1273 1.815 0.0862 .
## lag1 0.7605 0.1341 5.672 2.22e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 87.78 on 18 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.6412, Adjusted R-squared: 0.6213
## F-statistic: 32.17 on 1 and 18 DF, p-value: 2.221e-05
##
## The prediction for 2021 is the following
## 21
## 1452.333
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.2049787 1.571606 0.222
## Alternative hypothesis: rho != 0
##
##
## Team: Memphis.Grizzlies
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -51.046 -30.535 -2.213 28.174 81.629
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 860.0667 430.2933 1.999 0.08067 .
## lag1 0.9139 0.2815 3.246 0.01176 *
## lag2 0.4658 0.3783 1.231 0.25321
## lag3 -1.3497 0.3390 -3.982 0.00405 **
## lag4 0.2278 0.3471 0.656 0.53004
## lag5 0.6656 0.3564 1.868 0.09878 .
## lag6 -0.4960 0.2537 -1.955 0.08626 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 50.24 on 8 degrees of freedom
## (6 observations deleted due to missingness)
## Multiple R-squared: 0.8441, Adjusted R-squared: 0.7271
## F-statistic: 7.217 on 6 and 8 DF, p-value: 0.006801
##
## The prediction for 2021 is the following
## 21
## 1509.908
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.05160347 1.752942 0.272
## Alternative hypothesis: rho != 0
##
##
## Team: Philadelphia.76ers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -111.153 -24.370 -3.418 32.528 73.506
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 942.4675 394.9845 2.386 0.038213 *
## lag1 1.2578 0.2356 5.340 0.000328 ***
## lag2 -1.1063 0.3330 -3.323 0.007713 **
## lag3 0.8756 0.3471 2.523 0.030255 *
## lag4 -1.1389 0.3433 -3.317 0.007781 **
## lag5 0.4537 0.2501 1.814 0.099724 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 54.95 on 10 degrees of freedom
## (5 observations deleted due to missingness)
## Multiple R-squared: 0.8515, Adjusted R-squared: 0.7772
## F-statistic: 11.47 on 5 and 10 DF, p-value: 0.0006953
##
## The prediction for 2021 is the following
## 21
## 1563.759
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.1419326 1.661627 0.248
## Alternative hypothesis: rho != 0
##
##
## Team: Boston.Celtics
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -130.887 -47.102 6.087 42.326 139.743
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1628.8647 493.2323 3.302 0.00631 **
## lag1 0.5609 0.2378 2.358 0.03616 *
## lag2 -0.2759 0.2879 -0.959 0.35672
## lag3 0.1522 0.2856 0.533 0.60377
## lag4 -0.4906 0.2413 -2.033 0.06480 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 79.87 on 12 degrees of freedom
## (4 observations deleted due to missingness)
## Multiple R-squared: 0.4922, Adjusted R-squared: 0.3229
## F-statistic: 2.908 on 4 and 12 DF, p-value: 0.06778
##
## The prediction for 2021 is the following
## 21
## 1579.93
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.1064543 2.171657 0.958
## Alternative hypothesis: rho != 0
##
##
## Team: Cleveland.Cavaliers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -138.219 -43.604 4.571 27.044 203.068
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1873.53219 483.78968 3.873 0.00222 **
## lag1 0.57797 0.25270 2.287 0.04114 *
## lag2 -0.41174 0.29352 -1.403 0.18602
## lag3 0.06439 0.30560 0.211 0.83665
## lag4 -0.48065 0.25318 -1.898 0.08194 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 94.24 on 12 degrees of freedom
## (4 observations deleted due to missingness)
## Multiple R-squared: 0.6523, Adjusted R-squared: 0.5364
## F-statistic: 5.629 on 4 and 12 DF, p-value: 0.008678
##
## The prediction for 2021 is the following
## 21
## 1387.29
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.01576869 2.007691 0.848
## Alternative hypothesis: rho != 0
##
##
## Team: Charlotte.Hornets
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -127.020 -44.501 4.702 55.194 73.284
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1072.0092 293.3040 3.655 0.00214 **
## lag1 0.6590 0.2224 2.963 0.00916 **
## lag2 -0.4131 0.2017 -2.048 0.05739 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 61.01 on 16 degrees of freedom
## (2 observations deleted due to missingness)
## Multiple R-squared: 0.3621, Adjusted R-squared: 0.2823
## F-statistic: 4.541 on 2 and 16 DF, p-value: 0.02743
##
## The prediction for 2021 is the following
## 21
## 1383.525
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.02894974 1.962441 0.758
## Alternative hypothesis: rho != 0
##
##
## Team: Miami.Heat
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -165.01 -43.99 1.86 41.10 96.33
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1529.98383 410.00792 3.732 0.00223 **
## lag1 0.49283 0.24421 2.018 0.06317 .
## lag2 -0.07289 0.28220 -0.258 0.79994
## lag3 -0.40684 0.23953 -1.699 0.11152
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 78.57 on 14 degrees of freedom
## (3 observations deleted due to missingness)
## Multiple R-squared: 0.4874, Adjusted R-squared: 0.3775
## F-statistic: 4.437 on 3 and 14 DF, p-value: 0.02168
##
## The prediction for 2021 is the following
## 21
## 1582.32
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.09993848 1.768211 0.468
## Alternative hypothesis: rho != 0
##
##
## Team: Oklahoma.City.Thunder
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -140.701 -43.292 -6.108 68.452 147.915
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 512.1811 288.6448 1.774 0.09291 .
## lag1 0.6664 0.1859 3.584 0.00212 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 84.68 on 18 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.4164, Adjusted R-squared: 0.384
## F-statistic: 12.85 on 1 and 18 DF, p-value: 0.002121
##
## The prediction for 2021 is the following
## 21
## 1559.582
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.1132656 1.619931 0.27
## Alternative hypothesis: rho != 0
##
##
## Team: Los.Angeles.Lakers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -69.737 -49.630 -5.164 46.180 91.914
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 616.0668 206.7589 2.980 0.009945 **
## lag1 0.9351 0.2244 4.168 0.000949 ***
## lag2 0.2284 0.3485 0.656 0.522737
## lag3 -0.5602 0.2405 -2.330 0.035300 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 62.26 on 14 degrees of freedom
## (3 observations deleted due to missingness)
## Multiple R-squared: 0.8115, Adjusted R-squared: 0.7711
## F-statistic: 20.09 on 3 and 14 DF, p-value: 2.427e-05
##
## The prediction for 2021 is the following
## 21
## 1689.464
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.08234792 1.690125 0.322
## Alternative hypothesis: rho != 0
##
##
## Team: Denver.Nuggets
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -90.587 -17.687 -4.533 23.024 67.624
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 990.68086 384.88584 2.574 0.02770 *
## lag1 1.01817 0.27546 3.696 0.00413 **
## lag2 -0.56239 0.36279 -1.550 0.15214
## lag3 0.02476 0.28639 0.086 0.93281
## lag4 0.18452 0.26319 0.701 0.49923
## lag5 -0.30728 0.19439 -1.581 0.14502
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 43.69 on 10 degrees of freedom
## (5 observations deleted due to missingness)
## Multiple R-squared: 0.6956, Adjusted R-squared: 0.5434
## F-statistic: 4.57 on 5 and 10 DF, p-value: 0.0198
##
## The prediction for 2021 is the following
## 21
## 1589.593
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.1386837 2.249466 0.91
## Alternative hypothesis: rho != 0
##
##
## Team: Phoenix.Suns
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -151.253 -77.410 -8.986 55.595 183.052
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 509.1778 272.8555 1.866 0.07841 .
## lag1 0.6631 0.1806 3.672 0.00175 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 92.02 on 18 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.4282, Adjusted R-squared: 0.3964
## F-statistic: 13.48 on 1 and 18 DF, p-value: 0.001746
##
## The prediction for 2021 is the following
## 21
## 1445.768
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.1435297 1.477901 0.156
## Alternative hypothesis: rho != 0
##
##
## Team: Los.Angeles.Clippers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -88.811 -31.860 5.439 30.154 102.673
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 479.010068 234.760550 2.040 0.0606 .
## lag1 1.205356 0.223344 5.397 9.41e-05 ***
## lag2 -0.526619 0.306094 -1.720 0.1074
## lag3 0.009993 0.205811 0.049 0.9620
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 60.61 on 14 degrees of freedom
## (3 observations deleted due to missingness)
## Multiple R-squared: 0.7487, Adjusted R-squared: 0.6948
## F-statistic: 13.9 on 3 and 14 DF, p-value: 0.0001757
##
## The prediction for 2021 is the following
## 21
## 1635.527
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.01651286 1.966173 0.62
## Alternative hypothesis: rho != 0
##
##
## Team: Washington.Wizards
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -108.285 -16.176 7.182 37.253 54.742
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1301.36338 514.70081 2.528 0.0300 *
## lag1 0.75344 0.29876 2.522 0.0303 *
## lag2 -0.27651 0.31767 -0.870 0.4045
## lag3 0.05106 0.29459 0.173 0.8658
## lag4 -0.21457 0.29515 -0.727 0.4839
## lag5 -0.22006 0.27454 -0.802 0.4414
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 53.79 on 10 degrees of freedom
## (5 observations deleted due to missingness)
## Multiple R-squared: 0.7181, Adjusted R-squared: 0.5772
## F-statistic: 5.095 on 5 and 10 DF, p-value: 0.01398
##
## The prediction for 2021 is the following
## 21
## 1371.575
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.05418594 2.046179 0.818
## Alternative hypothesis: rho != 0
##
##
## Team: Detroit.Pistons
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -64.249 -31.104 -5.458 6.953 103.234
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 590.26365 358.09516 1.648 0.1379
## lag1 0.77344 0.29164 2.652 0.0292 *
## lag2 0.05017 0.37095 0.135 0.8958
## lag3 -0.01783 0.36535 -0.049 0.9623
## lag4 -0.37110 0.36455 -1.018 0.3385
## lag5 0.24931 0.37848 0.659 0.5286
## lag6 -0.09453 0.28305 -0.334 0.7470
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 63.83 on 8 degrees of freedom
## (6 observations deleted due to missingness)
## Multiple R-squared: 0.7314, Adjusted R-squared: 0.53
## F-statistic: 3.631 on 6 and 8 DF, p-value: 0.04826
##
## The prediction for 2021 is the following
## 21
## 1420.803
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.01487294 1.922345 0.506
## Alternative hypothesis: rho != 0
##
##
## Team: Indiana.Pacers
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -89.603 -28.607 -1.564 36.577 54.630
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1579.6909 481.3800 3.282 0.00656 **
## lag1 0.3621 0.2445 1.481 0.16434
## lag2 0.1419 0.2616 0.542 0.59748
## lag3 -0.2554 0.2603 -0.981 0.34598
## lag4 -0.2929 0.2442 -1.199 0.25352
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 47.88 on 12 degrees of freedom
## (4 observations deleted due to missingness)
## Multiple R-squared: 0.4788, Adjusted R-squared: 0.3051
## F-statistic: 2.756 on 4 and 12 DF, p-value: 0.07764
##
## The prediction for 2021 is the following
## 21
## 1536.01
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.07777077 1.801042 0.548
## Alternative hypothesis: rho != 0
##
##
## Team: Minnesota.Timberwolves
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -98.648 -38.581 -9.233 52.240 68.776
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1350.3939 459.1307 2.941 0.0187 *
## lag1 0.5536 0.2747 2.015 0.0787 .
## lag2 -0.1773 0.3095 -0.573 0.5824
## lag3 -0.2925 0.2918 -1.002 0.3456
## lag4 0.0145 0.3012 0.048 0.9628
## lag5 0.4705 0.2902 1.621 0.1436
## lag6 -0.5237 0.2462 -2.127 0.0661 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 69.18 on 8 degrees of freedom
## (6 observations deleted due to missingness)
## Multiple R-squared: 0.5645, Adjusted R-squared: 0.2379
## F-statistic: 1.728 on 6 and 8 DF, p-value: 0.2318
##
## The prediction for 2021 is the following
## 21
## 1363.549
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.2611788 2.388298 0.716
## Alternative hypothesis: rho != 0
##
##
## Team: Milwaukee.Bucks
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -178.289 -30.933 -4.362 27.501 158.328
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 449.6498 266.9548 1.684 0.10937
## lag1 0.6983 0.1797 3.885 0.00108 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 72.82 on 18 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.4561, Adjusted R-squared: 0.4259
## F-statistic: 15.09 on 1 and 18 DF, p-value: 0.001085
##
## The prediction for 2021 is the following
## 21
## 1646.317
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.0415015 1.910716 0.692
## Alternative hypothesis: rho != 0
##
##
## Team: Sacramento.Kings
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -72.88 -17.98 11.15 23.91 38.35
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1109.64864 377.45616 2.940 0.0187 *
## lag1 0.17796 0.32465 0.548 0.5985
## lag2 0.09916 0.31510 0.315 0.7610
## lag3 -0.07840 0.34851 -0.225 0.8276
## lag4 0.38162 0.45695 0.835 0.4279
## lag5 0.06601 0.46659 0.141 0.8910
## lag6 -0.42918 0.32963 -1.302 0.2291
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 42.95 on 8 degrees of freedom
## (6 observations deleted due to missingness)
## Multiple R-squared: 0.5545, Adjusted R-squared: 0.2204
## F-statistic: 1.66 on 6 and 8 DF, p-value: 0.2478
##
## The prediction for 2021 is the following
## 21
## 1434.024
##
## lag Autocorrelation D-W Statistic p-value
## 1 0.06412816 1.824452 0.458
## Alternative hypothesis: rho != 0
##
##
## Team: New.Orleans.Pelicans
##
## Call:
## lm(formula = mymodel, data = current_team)
##
## Residuals:
## Min 1Q Median 3Q Max
## -75.500 -34.169 -2.281 37.381 80.654
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2664.89637 990.70214 2.690 0.0275 *
## lag1 0.17128 0.31676 0.541 0.6034
## lag2 -0.13482 0.27207 -0.496 0.6336
## lag3 -0.22786 0.26847 -0.849 0.4207
## lag4 -0.29237 0.28088 -1.041 0.3284
## lag5 0.03403 0.27875 0.122 0.9059
## lag6 -0.35459 0.25807 -1.374 0.2067
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 63.89 on 8 degrees of freedom
## (6 observations deleted due to missingness)
## Multiple R-squared: 0.3871, Adjusted R-squared: -0.07252
## F-statistic: 0.8422 on 6 and 8 DF, p-value: 0.571
##
## The prediction for 2021 is the following
## 21
## 1466.278
##
## lag Autocorrelation D-W Statistic p-value
## 1 -0.05424297 2.042947 0.906
## Alternative hypothesis: rho != 0